package model.skill;

import java.util.ArrayList;
import java.util.HashSet;

import utilities.Archive;
import model.effect.ConstantChangeStatEffect;
import model.effect.Effect;
import model.entity.Entity;
import model.entity.stats.StatType;
import model.map.Location;
import utilities.*;

public class ProjectileSkill extends ActivateableSkill implements Archiveable {

	private Projectile projectile;
	private boolean inUse;
	
	public ProjectileSkill()
	{
		super(SkillType.PROJECTILE, SkillType.PROJECTILE, 0);
	}
	
	public ProjectileSkill(String name, String skillType, int cost, Projectile projectile, boolean inUse)
	{
		super(name, skillType, cost);
		this.projectile = projectile;
		this.inUse = inUse;
	}
	
	public void activate(Entity entity)
	{
		int cost = super.getCost();
		if(entity.getStat(StatType.MP).getValue() > cost && !inUse)
		{
			entity.getStats().addConstantModifier(StatType.MP, -cost);
			ProjectileInformation projectileInfo = new ProjectileInformation(entity.getLocation(), entity.getDirection());
			inUse = true;
			projectile.propagate(projectileInfo);
		}
		else
			;
		inUse = false;
	}
	
	public Projectile getProjectile()
	{
		return projectile;
	}
	
	public Archive save() {
		Archive archive = super.save();
		
		archive.putClassName("projectile", this.projectile.getClass().getName());
		archive.putOneRelationship("projectile", this.projectile);
		
		archive.putAttribute("inUse", Boolean.toString(this.inUse));
		
		return archive;
	}
	
	public void load(Archive archive) {
		super.load(archive);
		
		this.projectile = (Projectile)ModelFactory.getInstance().createInstanceWithClassName(archive.getClassName("projectile"));
		this.projectile.load(archive.getOneRelationship("projectile"));
		
		this.inUse = Boolean.parseBoolean(archive.getAttribute("inUse"));
	}
	
	public boolean getInUse()
	{
		return inUse;
	}
	
	public void setInUse(boolean inUse)
	{
		this.inUse = inUse;
	}
}
